package app.util.image
{
	import app.gui.control.*;
	import app.util.*;
	
	import flash.display.*;
	import flash.filesystem.*;
	
	import mx.collections.*;
	import mx.controls.*;
	
	public class ImageConfig
	{
		public static const JPEG_TYPE:int = 0;
		public static const PNG_TYPE:int = 1;
		public static const BMP_TYPE:int = 2;				
		
		public var file:File;
		public var fileType:int;
		
		public var scale:Number = 1.0;
		public var stateIndex:int = 1;
		[Bindable()]
		public var images:ArrayCollection = new ArrayCollection();
		[Bindable()]
		public var actions:ArrayCollection = new ArrayCollection();
		
		public function ImageConfig(org:BitmapData)
		{
			this.images.addItem(org);
			this.actions.addItem("Original Image");
		}
		
		public function pushState(data:BitmapData, desc:String):void
		{
			var len:int = this.images.length;
			if(this.stateIndex != len)
			{
				//Push to the current position, and clean the remaining
				while(this.stateIndex < len)
				{
					this.images.removeItemAt(this.stateIndex);
					this.actions.removeItemAt(this.stateIndex);
					len--;
				}
			}
			Mediator.alert("Image transform : " + desc);
			
			while(this.actions.contains(desc))
			{
				desc = desc + ' ';
			}
			this.images.addItem(data);
			this.actions.addItem(desc);
			this.gotoState(this.stateIndex + 1);
		}
		
		public function gotoState(i:int):void
		{
			if(i < 1) i = 1;
			if(i > this.images.length) i = this.images.length;
			if(i != this.stateIndex)
			{
				Mediator.getLogger().log("Historical actions goto : " + i);
				this.stateIndex = i;
				var list:ActionList = Mediator.getMain().actionList;
				list.selectedIndex = this.stateIndex - 1;
				list.scroll();
				Mediator.getCurrentAquaImage().loadImage();
			}
		}
		
		public function applyConfigToView():void
		{			
			var list:ActionList = Mediator.getMain().actionList;
			list.dataProvider = this.actions;
			list.selectedIndex = this.stateIndex - 1;
			
			Mediator.getMain().displayer.zoomSlider.value = this.scale;
		}
	}
}